<?php

/**
 * ECSHOP mobile前台公共函数
 * ============================================================================
 * 版权所有 2005-2010 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liuhui $
 * $Id: init.php 15013 2008-10-23 09:31:42Z liuhui $
*/
header('Cache-control: private');
header('Content-type: text/html; charset=utf-8');
//include_once(dirname(__FILE__).'/lib_page_refresh.php');//防止刷新
if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}
define('ECS_WAP', true);


/* 取得当前ecshop所在的根目录 */
define('ROOT_PATH', str_replace('sanse_wap_v2/api/includes/init.php', '', str_replace('\\', '/', __FILE__)));


if (DIRECTORY_SEPARATOR == '\\')
{
    @ini_set('include_path',      '.;' . ROOT_PATH);
}
else
{
    @ini_set('include_path',      '.:' . ROOT_PATH);
}

if (file_exists(ROOT_PATH . 'data/config.php'))
{
    include(ROOT_PATH . 'data/config.php');
}
else
{
    include(ROOT_PATH . 'includes/config.php');
}

if (defined('DEBUG_MODE') == false)
{
    define('DEBUG_MODE', 7);
}

if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}

$php_self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
if ('/' == substr($php_self, -1))
{
    $php_self .= 'index.php';
}
define('PHP_SELF', $php_self);
// require(ROOT_PATH . 'includes/url_jump.php');
require(ROOT_PATH . 'includes/cls_ecshop.php');
require(ROOT_PATH . 'includes/lib_base.php');
require(ROOT_PATH . 'includes/lib_common.php');
require(ROOT_PATH . 'includes/lib_time.php');
require(ROOT_PATH . 'includes/lib_main.php');
require(ROOT_PATH . 'mobile/includes/lib_main.php');
require(ROOT_PATH . 'includes/inc_constant.php');
require(ROOT_PATH . 'includes/cls_error.php');
require(ROOT_PATH . 'includes/lib_function.php');



/* 对用户传入的变量进行转义操作。*/
if (!get_magic_quotes_gpc())
{
    if (!empty($_GET))
    {
        $_GET  = addslashes_deep($_GET);
    }
    if (!empty($_POST))
    {
        $_POST = addslashes_deep($_POST);
    }

    $_COOKIE   = addslashes_deep($_COOKIE);
    $_REQUEST  = addslashes_deep($_REQUEST);
}

/* 创建 ECSHOP 对象 */
$ecs = new ECS($db_name, $prefix);

/* 初始化数据库类 */
require(ROOT_PATH . 'includes/cls_mysql.php');
$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);
$db_host = $db_user = $db_pass = $db_name = NULL;




/* 载入系统参数 */
$_CFG = load_config();

/* 初始化session */
require(ROOT_PATH . 'includes/cls_session.php');
$sess = new cls_session($db, $ecs->table('sessions'), $ecs->table('sessions_data'), 'ECS_ID');
define('SESS_ID', $sess->get_session_id());

// if (!defined('INIT_NO_SMARTY'))
// {
   

//     /* 创建 Smarty 对象。*/
//     require(ROOT_PATH . 'includes/cls_template.php');
//     $smarty = new cls_template;

//     $smarty->cache_lifetime = $_CFG['cache_time'];
//     $smarty->template_dir   = ROOT_PATH . 'mobile/templates';
//     $smarty->cache_dir      = ROOT_PATH . 'mobile/temp/caches';
//     $smarty->compile_dir    = ROOT_PATH . 'mobile/temp/compiled/mobile';
	
// 	$smarty->caching        = false;
//     if ((DEBUG_MODE & 2) == 2)
//     {
//         $smarty->direct_output = true;
//         $smarty->force_compile = true;
//     }
//     else
//     {
//         $smarty->direct_output = false;
//         $smarty->force_compile = false;
//     }
// }

// if (!defined('INIT_NO_USERS'))
// {
//     /* 会员信息 */
//     $user =& init_users();
		
//     if (empty($_SESSION['user_id']))
//     {
//         if ($user->get_cookie())
//         {
			
//             /* 如果会员已经登录并且还没有获得会员的帐户余额、积分以及优惠券 */
//             if ($_SESSION['user_id'] > 0 && !isset($_SESSION['user_money']))
//             {
//                 update_user_info();
//             }
//         }
//         else
//         {
//             $_SESSION['user_id']     = 0;
//             $_SESSION['user_name']   = '';
//             $_SESSION['email']       = '';
//             $_SESSION['user_rank']   = 0;
//             $_SESSION['discount']    = 1.00;
//         }
//     }
// }

// if ((DEBUG_MODE & 1) == 1)
// {
//     error_reporting(E_ALL);
// }
// else
// {
//     error_reporting(E_ALL ^ E_NOTICE);
// }
// if ((DEBUG_MODE & 4) == 4)
// {
//     include(ROOT_PATH . 'includes/lib.debug.php');
// }

// /* 判断是否支持gzip模式 */
// if (gzip_enabled())
// {
//     ob_start('ob_gzhandler');
// }


/* wap头文件 */
//if (substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/')) != '/user.php')
//{}
header("Content-Type:text/html; charset=utf-8");

if (empty($_CFG['wap_config']))
{
    echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>ECShop_mobile</title></head><body><p align='left'>对不起,{$_CFG['shop_name']}暂时没有开启手机购物功能</p></body></html>";
    exit();
}
include(ROOT_PATH . 'includes/weixin_function.php');

// require(dirname(__FILE__).'/config.php');
// require(dirname(__FILE__).'/function.php');
// require(dirname(__FILE__).'/inc_mobile_info.php');//品牌ID入口 -Yan -time-2016-02-23
// // require(ROOT_PATH.'mobile/includes/left_menu.php');//左侧菜单入口 
// require(dirname(__FILE__).'/cls_mobile_user.php');
// $mobile_user = new cls_mobile_user();
error_reporting(E_ERROR | E_WARNING | E_PARSE);


if(!empty($_COOKIE['ECS']['user_id'])){
	$user_id = $_COOKIE['ECS']['user_id'];
	$user_info = get_user_info($user_id);	
	
	// $user_info['cart_number'] =  getCartNumber();
	// $user_info['pay_points'] =   getUserPoints();
	// $user_info['user_rank'] =   getUserRank();
	
	// $smarty->assign('user_info', $user_info);
	
}

// include_once(dirname(__FILE__).'/cls_weixin_login.php');//微信登录盘dua
// $cls_weixin_login = new cls_weixin_login($user,$user_id);
// $cls_weixin_login->login();
$come_from = $_COOKIE['come_from'];
if($come_from&&$come_from !='weixin'){
	
	// $smarty->assign('showHeader', false);
	
}else{
	// $smarty->assign('showHeader', true);
}

$machine_info = $_COOKIE['MACHINE'];  
// $smarty->assign('site_title',$_CFG['shop_title']);
// $smarty->assign('app_title', $_CFG['shop_name']);
$cookie_id = $machine_info['cookie_id']?$machine_info['cookie_id']:$_COOKIE['ECS_ID'];


$http_user_agent = $_SERVER['HTTP_USER_AGENT'];
$http_agent = strtolower($http_user_agent);
$is_wechat_login = false;
if (strpos($http_agent, 'micromessenger')) {
 	$is_wechat_login = true;
}
// $smarty->assign('is_wechat_login', $is_wechat_login);
?>